package com.company.learnjpa.resources;

import com.company.learnjpa.model.entity.Role;
import com.company.learnjpa.model.entity.User;
import com.company.learnjpa.model.repository.RoleRepository;
import com.company.learnjpa.model.repository.UserRepository;
import jakarta.inject.Inject;
import jakarta.security.enterprise.identitystore.Pbkdf2PasswordHash;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 肖磊
 */
@Path("blogs")
public class LearnJpaResource {

    @Inject
    private UserRepository userRepository;

    @Inject
    private RoleRepository roleRepository;

    @Inject
    private Pbkdf2PasswordHash passwordHash;

    @GET
    @Path("users/{id}")
    @Produces("application/json")
    public User findUser(@PathParam("id") Long id) {
        return userRepository.findById(id);
    }

    @GET
    @Path("users")
    @Produces("application/json")
    public List<User> findAll() {
        return userRepository.findAll();
    }

    @GET
    @Path("roles")
    @Produces("application/json")
    public List<Role> findAllRoles() {
        return roleRepository.findAll();
    }

    @GET
    @Path("pwd")
    @Produces("application/json")
    public Map<String, String> getPass() {
        return Map.of("123456", passwordHash.generate("123456".toCharArray()));
    }

}
